﻿@using System.Data.Entity.Core.Metadata.Edm
@using NFine.Domain.Entity.Biz

@{
    ViewBag.Title = "我的订单";
    Layout = "~/Views/Shared/_LayoutWeui.cshtml";
}
@section heardStyle
{
    <!-- 字体图标 -->
    <link rel="stylesheet" href="~/Content/M/css/iconfonts.css" />
    <link rel="stylesheet" href="~/Content/M/css/list.css" />
    <style type="text/css">
        .weui-media-box_appmsg {
            display: -webkit-box;
            display: -webkit-flex;
            display: flex;
             -webkit-box-align:start; 
             -webkit-align-items:start; 
             align-items:flex-start; 
             margin-top:10px;
        }
        .shbtn {
            background-color:dodgerblue;
            color:#ffffff;
            line-height:34px;
            padding:3px 8px 3px 8px;
            margin-top:3px;
            border-radius:3px;

        }
    </style>
}
@*<header class="header">
    <span style="margin-left: 0.5rem;">
        <a href="javascript:location.replace('@ViewData["pre"]')">
            <span class="icon"></span>
        </a>
    </span>
    <span class="title"><strong>@ViewData["title"] </strong></span>
</header>*@
<div class="weui-navbar" style="position: fixed;   max-width:640px;">
    <a class="weui-navbar__item @(ViewData["nowType"].ToString() == "-3" ? " weui-bar__item--on" : "")" href="#" data-flag="-3">
        全部订单
    </a>
    <a class="weui-navbar__item @(ViewData["nowType"].ToString() == "1" ? " weui-bar__item--on" : "")" href="#" data-flag="1">
        待发货
    </a>
    <a class="weui-navbar__item @(ViewData["nowType"].ToString() == "2" ? " weui-bar__item--on" : "") " href="#" data-flag="2">
        已发货
    </a>
    <a class="weui-navbar__item @(ViewData["nowType"].ToString() == "3" ? " weui-bar__item--on" : "")" href="#" data-flag="3">
        已完成
    </a>
</div>



<div class="weui-panel_access" style="margin-top:46px; ">
</div>
<div class="weui-loadmore" id="divMore">
    <i class="weui-loading"></i>
    <span class="weui-loadmore__tips">正在加载...</span>
</div>
@section footScript
{
    <script type="text/javascript">
        //上拉加载更多
        var loading = false;  //状态标记
        var _page = 1;
        var _pageCount = 10;

        initMoreData();

        $(document.body).infinite().on("infinite", function () {
            if (loading) return;
            loading = true;
            _page++;
            initMoreData();
        });
        function initMoreData() {
            $.ajax({
                type: 'post',
                url: "getMoreOrders",
                data: {
                    "type": @ViewData["nowType"],
                    "pagenum": _page,
                    "count": _pageCount
                },
                dataType: 'json',
                success: function (_data) {
                    loading = false;
                    var _html = '';
                    if (_page == 1 && _data.length == 0) {
                        _html += ' <div class="norecord"><img src="/Content/M/img/wudingdan.png" /> <div> 暂无订单 </div> </div>';
                        $(".weui-panel_access").append(_html);
                        $(document.body).destroyInfinite();
                        $("#divMore").hide();
                    } else {
                        for (var i = 0, len = _data.length; i < len; i++) {
                            var order = _data[i];
                            var _btn="";
                                  
                            _html += '<a class="con">';
                            _html += ' <div class="weui-media-box pro">';
                            _html += ' <div style="margin-bottom:0.2rem;"> 订单编号：' + order.F_OrderCode;
                            _html += ' <span class="price right"> ';
                            switch (order.F_OrderStatus) {
                                case 0: _html += '未支付'; break;
                                case 1: _html += '准备发货';break;
                                case 2: _html += '正在途中';
                                    _btn = '<span class="shbtn" onclick="kdclick(\''+order.F_TransferCenterId+'\',\''+order.F_ProductId+'\')">物流信息</span>&nbsp;&nbsp;&nbsp;&nbsp;';
                                    _btn+='<span class="shbtn" onclick="btnclick(\''+order.F_Id+'\');">收货确认</span>' ;                                   
                                    break;
                                case 3: _html += '已完成'; break;
                            }
                            _html += ' </span></div>';
                            _html += ' <div class="weui-media-box_appmsg">';
                            _html += ' <div class="weui-media-box__hd" style="height:70px;width:70px">';
                            if (order.OrderItems != null && order.OrderItems[0].F_ThumbnailsUrl != "") {
                                order.ProductImageUrl = order.OrderItems[0].F_ThumbnailsUrl;//.replace('.', '_s.');
                            } else {
                                order.ProductImageUrl = "/Content/img/imgdefalt.jpg";
                            }
                            _html += '<img class="weui-media-box__thumb" src="' + order.ProductImageUrl + '" style="width:100%;height:100%">';
                            _html += ' </div>';
                            _html += ' <div class="weui-media-box__bd">';
                            _html += '  <div style="height:25px;">';
                            _html += order.OrderItems[0].F_ProductName ;
                            _html += ' </div>';                                                      
                            _html += ' <p class="weui-media-box__desc proName">订购人：' + order.F_Consignee + '    电话：'+order.F_ContactNumber+'</p>';                            
                            _html += ' <p class="weui-media-box__desc proName">下单时间：' + order.F_OrderTime +'</p>';                            
                          
                            _html += ' <p class="weui-media-box__desc proName">备注：' + (order.F_Remark?order.F_Remark:"") + '</p>';
                            _html += ' </div></div>';
                            _html += ' <div class="weui-media-box_appmsg"> <div class="weui-media-box__bd total">';
                            _html+=_btn;
                            _html += ' <span class="totalInfo">实付总额：<span class="price">￥' + order.F_ProductPrice.toFixed(2) + '</span> </span>';
                            _html += ' </div></div></div></div>';
                            _html += ' </a>';
                        }

                        $(".weui-panel_access").append(_html);
                        if (_data.length < 10) {
                            $(".weui-panel_access").after('  <div class="weui-footer" style="margin:1rem">--已经到底了--</div>');
                            $(document.body).destroyInfinite();
                            $("#divMore").hide();
                        }
                    }
                }
            });
        }

        $(function(){
            $(".weui-navbar a").each(function(index){
                if(!$(this).hasClass("weui-bar__item--on"))
                {
                    $(this).click(function(){
                        window.location.replace("OrderList?type="+$(this).attr("data-flag"));
                    });
                }
            });
        });

        function btnclick(ordercode){
            $.confirm("确认收货？", function() {
                $(".weui-loading").show();
                //点击确认后的回调函数
                $.ajax({
                    type: 'post',
                    url: "submitSH",
                    data: {
                        "ordercode": ordercode
                    },
                    dataType: 'text',
                    success: function (_data) {
                        $(".weui-loading").hide();
                        if (_data.toString().indexOf("success") > -1) {
                            window.location.reload();
                        }
                        else {
                            $.alert(_data.substr(6));
                        }
                    }});
            }, function() {
                //点击取消后的回调函数
            });
        }
        function kdclick(code,num){
            window.location.href="https://m.kuaidi100.com/app/query/?com="+code+"&nu="+num+"&coname=ruibu";
        }
    </script>
}